package com.runyu.cordova.plugin.barcode;

import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

public class AreaPoint {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public static JSONArray toJsonArray(List<AreaPoint> barcodeBounds) {
		if (barcodeBounds != null) {

			JSONArray jsonArray = new JSONArray();
			for (AreaPoint areaPoint : barcodeBounds) {
				JSONObject jsonObject = new JSONObject();
				try {
					jsonObject.put("x", areaPoint.getX());
					jsonObject.put("y", areaPoint.getY());
				} catch (Exception e) {
					e.printStackTrace();
				}
				jsonArray.put(jsonObject);
			}

			return jsonArray;
		}
		return null;
	}
}
